'use strict';
const db = uniCloud.database();
const Response = require('response');
//添加文章
await function addArticle(params){
	var res =await db.collection("opendb-news-articles").add({
		user_id: params.uid,
		title: params.title,
		content: params.content,
		article_status: 0,
		view_count: 0,
		like_count: 0,
		is_sticky: 1,
		comment_status: 0,
		comment_count: 0
	});
	return Response({type:'success'})
}
//更新视频浏览量
await function addViewsCount(params){
	
	return Response({type:'success'})
}
await function removeArticle(params){
	var res = await db.collection("opendb-news-articles").where({_id:params.id}).remove();
	return Response({type:'success'})
}
exports.main = async (params, context) => {
	//event为客户端上传的参数
	let res = {},type=params.type;
	switch(type){
		case('add'):res = addArticle(params.data);break;
		case('views'):res = viewsArticle(params.data);break;
		default:res = Response({type:'success'});
	}
	//返回数据给客户端
	return res;
};
